#include<bits/stdc++.h>
using namespace std;
const int maxn=1000010;
int n,m,l,w;
void solve(){
    int rod[maxn];
    for(int i=0;i<maxn;i++)rod[i]=0;
    cin>>n>>m>>l>>w;
    vector<int>d(n),v(n),a(n);
    vector<int>p(m);
    vector<int>g(n);
    vector<int>f(n);
    int ans1=0,ans2=0;
    for(int i=0;i<n;i++){
        cin>>d[i]>>v[i]>>a[i];
        f[i]=0;
    }
    for(int i=0;i<m;i++){
        cin>>p[i];
        rod[p[i]]=1;
    }

    int s=0;
    for(int i=0;i<l;i++){
        if(rod[i]!=0){
            s++;
        }
        rod[i]=s;
    }

    for(int i=0;i<n;i++){
        int x=w*w-(v[i]*v[i]);
        int y;
        if(a[i]==0){
            if(v[i]<=w)g[i]=l+2;
            else{
                g[i]=l;
                f[i]==1;
                ans1++;
            }
        }
        else if(a[i]<0){
            y=2*a[i];
            if(v[i]>=w){
                g[i]=d[i]+x/y;
            }
            else g[i]=l+1;
            if(rod[g[i]]-rod[d[i]]-1!=0&&v[i]>w){
                ans1++;
                f[i]=1;
            }
        }
        else{
            y=2*a[i];
            g[i]=d[i]+x/y+1;
            if(rod[g[i]]-rod[d[i]]-1!=0){
                ans1++;
                f[i]=1;
            }
        }
    }

    int left=0,right=l;
    for(int i=0;i<n;i++){
        if(a[i]<=0&&f[i]==1){
            right=min(right,g[i]);
        }
        else if(a[i]>0&&f[i]==1){
            left=min(left,d[i]);
        }
    }
    for(int i=0;i<m;i++){
        if(p[i]>=left&&p[i]<=right)ans2++;
    }
    cout<<ans1<<' '<<m-ans2<<endl;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    while(t--)solve();
    return 0;
}
